package rank1400;

/**
 * 2744. 最大字符串配对数目
 */
public class No2744 {
    public int maximumNumberOfStringPairs(String[] words) {
        int n = words.length, ans = 0;
        boolean[] paired = new boolean[n];
        label:
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (paired[i] || paired[j]) continue;
                if (isSame(words[i], words[j])) {
                    ans++;
                    paired[j] = true;
                    continue label;
                }
            }
        }
        return ans;
    }

    private boolean isSame(String a, String b) {
        int n = a.length();
        if (n != b.length()) return false;
        for (int i = 0; i < n; i++) {
            if (a.charAt(i) != b.charAt(n - i - 1)) return false;
        }
        return true;
    }
}
